package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.admin.request.SwitchRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.entity.CurrentAffairs;
import com.sc.nft.entity.dto.CurrentAffairsAddDTO;
import com.sc.nft.entity.dto.CurrentAffairsAdminDTO;
import com.sc.nft.entity.dto.CurrentAffairsDetailsDTO;
import com.sc.nft.entity.vo.CurrentAffairsAdminVO;
import com.sc.nft.entity.vo.CurrentAffairsDetailsVO;
import com.sc.nft.service.CurrentAffairsService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 时政要闻表服务控制器
 *
 * @author zhangchao
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-03-05 10:52:52
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/currentAffairs")
@Api(tags = "资讯管理")
public class CurrentAffairsController {
    private final CurrentAffairsService currentAffairsService;

    @ApiOperation(value = "资讯列表", notes = "资讯列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsVoPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<CurrentAffairsAdminVO> currentAffairsVoPage(@Valid @RequestBody CurrentAffairsAdminDTO currentAffairsDTO) {
        return PageResult.success(currentAffairsService.adminCurrentAffairsVoPage(currentAffairsDTO));
    }

    @ApiOperation(value = "发布资讯", notes = "发布资讯", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsAdd", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsAdd(@Valid @RequestBody CurrentAffairsAddDTO currentAffairsAddVO) {
        currentAffairsService.currentAffairsAdd(currentAffairsAddVO);
        return Result.success();
    }

    @ApiOperation(value = "资讯详情", notes = "资讯详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<CurrentAffairsDetailsVO> currentAffairsDetails(@Valid @RequestBody IdRequest idRequest) {
        return Result.success(currentAffairsService.currentAffairsAdminDetails(idRequest.getId()));
    }

    @ApiOperation(value = "资讯修改", notes = "资讯修改", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsUpdate", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsUpdate(@Valid @RequestBody CurrentAffairsDetailsDTO currentAffairsDetailsDTO) {
        CurrentAffairs currentAffairs = BeanUtil.copyProperties(currentAffairsDetailsDTO, CurrentAffairs.class);
        currentAffairsService.currentAffairsUpdate(currentAffairs);
        return Result.success();
    }

    @ApiOperation(value = "删除", notes = "删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsDelete", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsDelete(@Valid @RequestBody IdRequest idRequest) {
        currentAffairsService.currentAffairsDelete(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "展示开关", notes = "展示开关", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsShow", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsShow(@Valid @RequestBody SwitchRequest switchRequest) {
        currentAffairsService.currentAffairsShow(switchRequest.getId(), switchRequest.getSwitchRequest());
        return Result.success();
    }

    @ApiOperation(value = "推荐位开关", notes = "推荐位开关", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsRecommend", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsRecommend(@Valid @RequestBody SwitchRequest switchRequest) {
        currentAffairsService.currentAffairsRecommend(switchRequest.getId(), switchRequest.getSwitchRequest());
        return Result.success();
    }


}